﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Collections;
using GPCSC.Web;
using NickLee.Common;

namespace GPCSC.Web.sjsbyes
{
    public partial class MYMQ : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                f_buildGrid();
            }
        }
        protected void f_buildGrid()
        {

            Hashtable htable = new Hashtable();
            byte[] userInfo = (byte[])base.o_baseTable[c_obj.s_userInfo];
            Hashtable userInfoTable = CompressData.UnCompressHashtable(userInfo);
            Model.CL_USER_S users = (Model.CL_USER_S)userInfoTable["SYS_USER"];
            htable.Add("@lgid", users.CL_USER_SOID.ToString());
            DataSet ds = new DataReturn().ReturnData(htable, "sel_MQlister_all");

            if (ds != null)
            {
            //    if (ds.Tables[0].Rows.Count > 0)
            //    {
            //        foreach (DataRow dbRow in ds.Tables[0].Rows)
            //        {
            //            if (dbRow["IsTj"].ToString() == "0")
            //            {
            //                dbRow["istjs"] = "<div style=\" cursor:pointer;\" onclick='tj(\"" + dbRow["tabids"].ToString() + "\")'>[推荐]</div>";
            //            }
            //            else
            //            {
            //                dbRow["istjs"] = "<div style=\" cursor:pointer;color:red;\">[已推荐]</div>";
            //            }
            //            if (dbRow["MQRJ"].ToString().Length > 20)
            //            {
            //                dbRow["mqrj"] = dbRow["MQRJ"].ToString().Substring(0, 20) + "......";
            //            }
            //            else
            //            {
            //                dbRow["mqrj"] = dbRow["MQRJ"].ToString();
            //            }
            //        }
            //    }
                PostListS.DataSource = ds;
                PostListS.DataBind();
                this.pageinfo.InnerHtml = new FYpage().GetPageNum(ds.Tables[0], PostListS, 10);

            }
        }
        /// <summary>
        /// Callback异步加载数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void LCallBack_Callback(object sender, NickLee.Web.UI.CallBackEventArgs e)
        {
            SqlReadXml org = new SqlReadXml();
            try
            {
                #region 删除数据
                if (Usual.f_convertString(e.Parameters[0]) == "3")
                {
                    SqlReadXml Org = new SqlReadXml();
                    var allname = "";
                    var deptname = "";
                    try
                    {

                        var zid = Usual.f_convertString(e.Parameters[2]);
                        if (zid == "" || zid == null)
                        {

                        }
                        base.o_uiTable.Clear();
                        base.o_uiTable.Add("@HDId", zid);


                        Org.NotDoSQL("del_mqlister_byid", base.o_uiTable);
                        this.f_buildGrid();

                    }

                    catch (System.Exception ee)
                    {


                        hfError.Value = lblProcesserMsg.Text = "删除数据失败!" + ee.Message;

                    }
                }
                else if (Usual.f_convertString(e.Parameters[0]) == "sel")
                {
                    byte[] userInfo = (byte[])base.o_baseTable[c_obj.s_userInfo];
                    Hashtable userInfoTable = CompressData.UnCompressHashtable(userInfo);
                    Model.CL_USER_S users = (Model.CL_USER_S)userInfoTable["SYS_USER"];
                    string gj = e.Parameters[1].ToString().Trim();
                    //string likess = e.Parameters[2].ToString().Trim();
                    //likes = "%" + likes + "%";
                    //likess = "%" + likess + "%";
                    //select b.*  from FK_MQ b where b.mqtitle like @like and b.mqrj like @likes and b.lgid = @lgid  and b.Isdel = 0
                    

                    string kdate = e.Parameters[2].ToString().Trim();
                    string  jdate = e.Parameters[3].ToString().Trim();
                    
                    string sql = "";
                    sql += "select b.*  from FK_MQ b";
                    sql += " where 1=1";
                    if (gj != "" && gj != null)
                    {
                        sql += " and(b.mqtitle like '%" + gj + "%' or b.mqrj like '%" + gj + "%' )";
                    }
                    if (kdate != null && kdate != "")
                    {
                        sql += " and cast('"+kdate+"' as datetime)< cast(b.mqdate as datetime) ";
                    }
                    if (jdate != null && jdate != "")
                    {
                        sql += " and cast('" + jdate + "' as datetime)> cast(b.mqdate as datetime)";
                    }
                    sql += " and b.lgid = '" + users.CL_USER_SOID.ToString() + "'  and b.Isdel = 0";
                    //Hashtable htable = new Hashtable();
                    //htable.Add("@like", likes);
                    //htable.Add("@likes", likess);


                    //htable.Add("@lgid", users.CL_USER_SOID.ToString());
                    //SqlReadXml Org = new SqlReadXml();
                    //DataSet ds = Org.ReaderDataSet("sel_MQlist_bylikeers", htable);
                    DataSet ds = Maticsoft.DBUtility.DbHelperSQL.Query(sql);
                    if (ds != null)
                    {

                        PostListS.DataSource = ds;
                        PostListS.DataBind();
                        this.pageinfo.InnerHtml = new FYpage().GetPageNum(ds.Tables[0], PostListS, 10);

                    }
                }

                else if (Usual.f_convertString(e.Parameters[0]) == "4")
                {
                    SqlReadXml Org = new SqlReadXml();
                    var allname = "";
                    var deptname = "";
                    try
                    {

                        var zid = Usual.f_convertString(e.Parameters[2]);
                        if (zid == "" || zid == null)
                        {

                        }
                        base.o_uiTable.Clear();


                        base.o_uiTable.Add("IsTj", 1);
                        // base.o_uiTable.Add("TjDate", DateTime.Now);
                        SQLServerDAL.databyhtable Dat = new SQLServerDAL.databyhtable();
                        Dat.databyhtables(o_uiTable, "update", "WW_MQ", "tabids", zid);
                        //Org.NotDoSQL("tj_mqlist_byid", base.o_uiTable);
                        this.f_buildGrid();


                    }

                    catch (System.Exception ee)
                    {


                        hfError.Value = lblProcesserMsg.Text = "推荐日记失败!" + ee.Message;

                    }
                }
                else if (Usual.f_convertString(e.Parameters[0]) == "2")
                {
                    SqlReadXml Org = new SqlReadXml();//
                    var zid = Usual.f_convertString(e.Parameters[2]);
                    if (zid == "" || zid == null)
                    {
                        this.f_buildGrid();
                    }
                    else
                    {
                        string likes = e.Parameters[2].ToString().Trim();
                        likes = "%" + likes + "%";
                        Hashtable htable = new Hashtable();
                        htable.Add("@like", likes);

                        byte[] userInfo = (byte[])base.o_baseTable[c_obj.s_userInfo];
                        Hashtable userInfoTable = CompressData.UnCompressHashtable(userInfo);
                        Model.CL_USER_S users = (Model.CL_USER_S)userInfoTable["SYS_USER"];
                        htable.Add("@lgid", users.CL_USER_SOID.ToString());

                        DataSet ds = Org.ReaderDataSet("sel_MQlist_bylikeer", htable);
                        if (ds != null)
                        {
                            //if (ds.Tables[0].Rows.Count > 0)
                            //{
                            //    foreach (DataRow dbRow in ds.Tables[0].Rows)
                            //    {
                            //        if (dbRow["IsTj"].ToString() == "0")
                            //        {
                            //            dbRow["istjs"] = "<div style=\" cursor:pointer;\" onclick='tj(\"" + dbRow["tabids"].ToString() + "\")'>[推荐]</div>";
                            //        }
                            //        else
                            //        {
                            //            dbRow["istjs"] = "<div style=\" cursor:pointer;color:red;\">[已推荐]</div>";
                            //        }
                            //        if (dbRow["MQRJ"].ToString().Length > 20)
                            //        {
                            //            dbRow["mqrj"] = dbRow["MQRJ"].ToString().Substring(0, 20) + "......";
                            //        }
                            //        else
                            //        {
                            //            dbRow["mqrj"] = dbRow["MQRJ"].ToString();
                            //        }
                            //    }
                            //}
                            PostListS.DataSource = ds;
                            PostListS.DataBind();
                            this.pageinfo.InnerHtml = new FYpage().GetPageNum(ds.Tables[0], PostListS, 10);

                        }

                    }
                }

                #endregion
            }
            catch (System.Exception pexp)
            {
                throw (pexp);
            }
            //最后进行Grid数据查询并填充
            finally
            {

                LPanel.RenderControl(e.Output);
            }
        }
    }
}